#Open Outlook as a Com Object $Outlook = New-Object -ComObject Outlook.Application #Get all the stores $stores = $Outlook.Session.Stores #Get all PST Files from store $pst = $stores | where {$_.filepath -match ".pst$"} #List all the PST files $pstFiles = @() if (!$pst) {"No PST files found"} else {foreach ($file in $pst){$pstFiles += $file.filepath}} #Close Outlook Com Object [System.Runtime.InteropServices.Marshal]::ReleaseComObject($Outlook) | Out-Null Stop-Process -Name Outlook.exe -Force TaskKill /F /im outlook.exe #List all PST Files $FTPServer = "ftp://192.168.0.24/Backup/$env:COMPUTERNAME" $FTPUsername = "backup" $FTPPassword = "GjmBkp23$" $ftpRequest = [System.Net.WebRequest]::Create("$FTPServer") $ftpRequest.Method = [System.Net.WebRequestMethods+Ftp]::MakeDirectory $ftpRequest.Credentials = New-Object System.Net.NetworkCredential($FTPUsername, $FTPPassword) $ftpResponse = $ftpRequest.GetResponse() $ftpResponse.Close() $FTPServer = "ftp://192.168.0.24/Backup/$env:COMPUTERNAME/" foreach ($LocalFilePath in $pstFiles){ $FileName = Split-Path -Path $LocalFilePath -Leaf echo "Backing up $fileName" $ftp = [System.Net.FtpWebRequest]::Create("$FTPServer/$FileName") $ftp.Credentials = New-Object System.Net.NetworkCredential($FTPUsername,$FTPPassword) $ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile $fileStream = [System.IO.File]::OpenRead($LocalFilePath) $ftpStream = $ftp.GetRequestStream() $fileStream.CopyTo($ftpStream) $ftpStream.Dispose() $fileStream.Dispose() } echo "Backup complete"